﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace JKF.Substructure
{
    public class SystemCmd
    {
        public static string ExecCommand(IEnumerable<string> cmds)
        {
            Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            string pingrst;
            p.Start();
            foreach (var cmd in cmds)
            {
                p.StandardInput.WriteLine(cmd);
            }
            p.StandardInput.WriteLine("exit");

            string strRst = p.StandardOutput.ReadToEnd();

            p.Close();
            return strRst;
        }

        public static string ExecCommand(string cmd)
        {
            return ExecCommand(new string[] { cmd });
        }
    }
}
